package com.healthcare.cameraview.config;

import com.healthcare.cameraview.ws.VideoWebSocketHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.beans.factory.annotation.Value;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Value("${qwen.api-key}")
    private String qwenApiKey;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new VideoWebSocketHandler(), "/ws/video")
                .setAllowedOrigins("*"); // 在生产环境中应该限制允许的源
    }

    @Bean("qwenApiKey")
    public String qwenApiKey() {
        return qwenApiKey;
    }
}
